package com.feng.mvc.controller;

import com.feng.mvc.bean.User;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/params")
public class ParamsController {
    @RequestMapping(value = "/params",params = {"name=123","!pwd"},headers = {"host=localhost:8080"})
//    @RequestMapping(value = "/params",params = {"name=123","pwd"})
    public String TestParams(){
        return "params";
    }

    @RequestMapping(value = "/test1")
    public String Test1(){
        return "params";
    }

    @RequestMapping(value = "/test2")
    public String Test2(HttpServletRequest request){
        String name = request.getParameter("name");
        String password = request.getParameter("password");
        System.out.println("name: "+name+"\npassword: "+password);
        return "params";
    }


    @RequestMapping(value = "/test3")
    public String Test3(String name,String password){
        System.out.println("name: "+name+"\npassword: "+password);
        return "params";
    }

    @RequestMapping("/test4")
    public String Test4(@RequestParam(value="user_name",defaultValue = "xxx") String name,
                        @RequestParam(value = "password",required = false) String password,
                        @RequestHeader(value = "haha",defaultValue = "kkk",required = false)String host,
//                        @CookieValue(value = "JSESSIONID")String JSESSIONID){
                        @CookieValue(value = "Cookie")String JSESSIONID){
        System.out.println("name: "+name+"\npassword: "+password);
        System.out.println("HOST: "+host);
        System.out.println("JSESSIONID "+JSESSIONID);
        return "params";
    }

    @RequestMapping("/testBean")
    public String TestBean(User user){
        System.out.println(user);
        return "success";
    }

}
